/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import java.util.List;
import models.Payment;
import models.Course;
import models.User;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Kjeld
 */
public class PaymentDao {
    private final Session session;
    
    public PaymentDao(Session session) {
        this.session = session;
    }
    
      public List<Payment> findAll() {
        Transaction tx = session.beginTransaction();
        List<Payment> list = session.createQuery("from Payment").list();
        tx.commit();
        return list;
    }
    
    public void save(Payment payment) {
        Transaction tx = session.beginTransaction();
        session.save(payment);
        tx.commit();
    }

    public void update(Payment payment) {
        Transaction tx = session.beginTransaction();
        session.update(payment);
        tx.commit();
    }

    public Payment get(long id) {
        return (Payment) session.get(Payment.class, id);
    }
    
    public void delete(Payment payment) {
        Transaction tx = session.beginTransaction();
        session.delete(payment);
        tx.commit();
    }
}
